class Solution
{
public:
    vector<string> getFolderNames(vector<string> &names)
    {
        unordered_map<string, int> usedCount;
        unordered_set<string> used;
        vector<string> ans;
        for (auto &name : names)
        {
            if (used.count(name))
            {
                int postfix = usedCount[name];
                while (true)
                {
                    ++postfix;
                    string newName = name + "(" + to_string(postfix) + ")";
                    if (!used.count(newName))
                    {
                        ans.push_back(newName);
                        used.insert(newName);
                        usedCount[name] = postfix;
                        break;
                    }
                }
            }
            else
            {
                ans.push_back(name);
                used.insert(name);
            }
        }
        return ans;
    }
};